package com.heima.skydemo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.skydemo.domin.common.PageResult;
import com.heima.skydemo.domin.dto.CategoryPageQueryDTO;
import com.heima.skydemo.entity.Category;
import com.heima.skydemo.mapper.CategoryMapper;
import com.heima.skydemo.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-04-15
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = new PageResult();
        int page = categoryPageQueryDTO.getPage();
        int pageSize = categoryPageQueryDTO.getPageSize();
        //开始分页查询
        PageHelper.startPage(page, pageSize);
        Page<Category> pageQuery = categoryMapper.pageQuery(categoryPageQueryDTO);

        //查询结果
        pageResult.setTotal(pageQuery.getTotal());
        pageResult.setRecords(pageQuery.getResult());


        return pageResult;
    }
}
